package com.lion.tag.input;

import java.io.IOException;

import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import com.lion.tag.LionInputTag;
import com.lion.tag.util.AppendUtil;

public class TextBox extends LionInputTag {
	private String onChange;
	private Boolean validate;// easyui-validatebox textbox
	private String validType;
	private boolean multiline = false;// 多行
	private String icon;
	private boolean password = false;

	/**
	 * 实现输入框
	 */
	@Override
	public void doTag() throws JspException, IOException {
		JspWriter out = getJspContext().getOut();
		StringBuilder sb = new StringBuilder(200);
		sb.append("<input ");
		AppendUtil.addAttribute(sb, "id", id);
		if (name != null && !name.equals("")) {
			AppendUtil.addAttribute(sb, "name", name);
		}
		boolean isValidatebox = false;
		if (validate != null && validate) {
			sb.append("class=\"easyui-validatebox textbox\" ");
		} else {
			sb.append("class=\"easyui-textbox\" ");
			isValidatebox = true;
		}
		if (password) {
			sb.append("type=\"password\" ");
		}
		if (required) {
			sb.append("required ");
		}
		sb.append("data-options=\"");
		boolean hasData = false;
		if (isValidatebox) {
			sb.append("validType:'");
			sb.append(validType);
			sb.append("'");
			hasData = true;
		}
		if (prompt != null && !prompt.equals("")) {
			if (hasData) {
				sb.append(",");
			}
			sb.append("prompt:'");
			sb.append(prompt);
			sb.append("'");
		}
		if (icon != null && !icon.equals("")) {
			if (hasData) {
				sb.append(",");
			}
			sb.append("iconCls:'");
			sb.append(icon);
			sb.append("',iconWidth: 22,");
		}
		if (multiline) {
			if (hasData) {
				sb.append(",");
			}
			sb.append("multiline:");
			sb.append(multiline);
		}
		sb.append("\" ");
		AppendUtil.addAttribute(sb, "value", value);
		AppendUtil.addAttribute(sb, "onChange", onChange);
		AppendUtil.addAttribute(sb, "style", style);
		if (maxlength != null) {
			AppendUtil.addAttribute(sb, "maxlength", maxlength + "");
		}
		sb.append("/>");
		out.write(sb.toString());
	}

	public String getOnChange() {
		return onChange;
	}

	public void setOnChange(String onChange) {
		this.onChange = onChange;
	}

	public Boolean getValidate() {
		return validate;
	}

	public void setValidate(Boolean validate) {
		this.validate = validate;
	}

	public String getValidType() {
		return validType;
	}

	public void setValidType(String validType) {
		this.validType = validType;
	}

	public boolean isMultiline() {
		return multiline;
	}

	public void setMultiline(boolean multiline) {
		this.multiline = multiline;
	}

	public String getIcon() {
		return icon;
	}

	public void setIcon(String icon) {
		this.icon = icon;
	}

	public boolean isPassword() {
		return password;
	}

	public void setPassword(boolean password) {
		this.password = password;
	}

}
